﻿using System.Collections.Generic;
using System.Windows.Forms;

namespace Logistics
{
    public class MyForms
    {
        /// <summary>
        /// 用户信息
        /// </summary>
        public static Model.tc_User User { get; set; }
        /// <summary>
        /// 按钮权限
        /// </summary>
        public static List<Model.tc_Permission> ButtonPermissions { get; set; }
        public static bool CheckChildFrmExist(Form myform, string childFrmName)
        {
            foreach (Form childFrm in myform.MdiChildren)
            {
                if (childFrm.Name == childFrmName) //用子窗体的Name进行判断，如果存在则将他激活
                {
                    if (childFrm.WindowState == FormWindowState.Minimized)
                        childFrm.WindowState = FormWindowState.Normal;
                    childFrm.Activate();
                    childFrm.Show();
                    return true;
                }
            }
            return false;
        }

        public static bool CloseChildFrm(Form myform, string childFrmName)
        {
            foreach (Form childFrm in myform.MdiChildren)
            {
                if (childFrm.Name == childFrmName)
                {
                    childFrm.Close();
                    return true;
                }
            }
            return false;
        }

        public static ListViewItem FindItemWithTag(ListView listInfo, string findtag)
        {
            var list = listInfo.Items;
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].Tag.ToString() == findtag)
                    return list[i];
            }
            return null;
        }
    }
}
